package com.memoir.common.response;

import com.memoir.model.enums.ResponseConstantEnums;

import java.io.Serializable;
public class ServerResponse implements Serializable {
    private String code;
    private String msg;
    private Object data;
    public ServerResponse() {}

    public static ServerResponse buildSuccess(ResponseConstantEnums enums){
        return buildObejct(enums);
    }


    public static ServerResponse buildSuccess(ResponseConstantEnums enums,Object data){
        ServerResponse response = buildObejct(enums);
        response.setData(data);
        return response;
    }


    public static ServerResponse buildError(ResponseConstantEnums enums){
        return buildObejct(enums);
    }
    public static ServerResponse buildError(String code,String msg){
        ServerResponse response = new ServerResponse();
        response.setCode(code);
        response.setMsg(msg);
        return response;
    }
    private static ServerResponse buildObejct(ResponseConstantEnums enums){
        ServerResponse response = new ServerResponse();
        response.setCode(enums.getCode());
        response.setMsg(enums.getMsg());
        return response;
    }

    public static ServerResponse buildSuccess(Object data){
        ServerResponse response = buildObejct(ResponseConstantEnums.SUCCESS);
        response.setData(data);
        return response;
    }


    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
